package org.teammach.laddercomp.shared;

import java.util.ArrayList;
import java.util.List;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.google.appengine.api.datastore.Key;

@PersistenceCapable(detachable = "true")
public class Ladder {

	public Ladder(String user, String commentary, List<String> teams) {
		// super();
		this.user = user;
		this.commentary = commentary;
		this.teams = teams;
		this.currentScore = -1;
	}

	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	private Key key;

	@Persistent
	String user;

	@Persistent
	String commentary;

	@Persistent
	List<String> teams;

	@Persistent
	Integer currentScore;

	@Persistent
	List<Integer> prevRounds;

	public String getUser() {
		return user;
	}

	public void setUser(String user) {
		this.user = user;
	}

	public String getCommentary() {
		return commentary;
	}

	public void setCommentary(String commentary) {
		this.commentary = commentary;
	}

	public List<String> getTeams() {
		return teams;
	}

	public void setTeams(List<String> teams) {
		this.teams = teams;
	}

	public Integer getCurrentScore() {
		return currentScore;
	}

	public void setCurrentScore(int currentScore) {
		this.currentScore = currentScore;
	}

	public List<Integer> getPrevRounds() {
		return prevRounds;
	}

	public void setPrevRounds(List<Integer> prevRounds) {
		this.prevRounds = prevRounds;
	}
	
	public void setScoreForPrevious(int round, int score) {
		while(prevRounds.size() < round+1) { prevRounds.add(-101); };
		prevRounds.set(round, score);
	}

}
